/**
 * Created by Administrator on 2016/1/20.
 */
define("wangwu/sxyc/getData",
    [
        'dojo/on',
        'dojo/query',
        'dojo/dom-construct',
        'dojo/_base/lang',
        'dojo/_base/declare',

        "esri/graphic",
        'esri/layers/GraphicsLayer'
    ],
    function(on,djQuery,domConstruct,lang,declare,
             Graphic,GraphicsLayer){
        var d = declare(null,{
            declaredClass:'wangwu.sxyc.getData',
            constructor:function(map,o){
                //this.appmap = map;
                this.map =map;
                this.option={
                    layerid:"支渠"
                };
                (o)?lang.mixin(this.option, o):0;
                this.initialized = false;
                //测试用
                //this.buttonId = 'testDojo-'+parseInt(Math.random()*1000);
                //domConstruct.create('div', {
                //    'id':'aaaa1111',
                //    'style':'position:absolute;right:20px;top:130px;width:100px',
                //    'innerHTML':'<input type="button" value="get" id="'+this.buttonId+'"/>'
                //}, map.id);
                //var button = djQuery('#'+this.buttonId);
                //on(button, 'click', lang.hitch(this, this.getData));
            },
            //-----------------------public----------------------------------

            init:function(){
                if (this.initialized) return;
                this.initialized = true;
                this._init();
            },
            setDataSource:function(o){
                (o)?lang.mixin(this.option, o):0;
            },
            getData:function(){
                var data = this._getData();
                return data;
            },
            //-----------------------private----------------------------------
            _init:function(){
            },
            _getData:function(){
                var layer = this.map.getLayer(this.option.layerid);
                //console.log(this.option.layerid);
                var attr,geo,graphicData;
                var data = [];
                //var layer = evt.target.layer;
                //console.log("getData", layer);
                var graphics = layer.graphics;
                for(var i = 0;i<graphics.length;i++){
                    attr=graphics[i].attributes;
                    geo=graphics[i].geometry;
                    graphicData ={
                        "attr":attr,
                        "geo":geo
                    };
                    data.push(graphicData);
                }
                var result = JSON.stringify(data);
                //console.log(result);
                return data;
            }
        });
        return d;

    })